﻿@{
    ViewBag.Title = "ReViewIndex";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<script type="text/javascript">
    $(function () {
        if ($("#categoryType").val() != null && $("#categoryType").val() != "") {
            categoryChange();
        }
    })
    function categoryChange() {
        var link = $('#UpdateCatLink');
        var select = $('#categoryType');
        var dbID = $('#dbID').val();
        var dbCode = $('#dbName').val();
        var urlstr = "@Html.Raw(Url.Action("GetCategroyList", "SingleSearch"))?id=" + dbID + "&type=" + select.val() + "&dbName=" + dbCode;
        link.attr("href", urlstr);
        link.click();
    }
    function search() {
        $('#pageIndexNow').val('1');
        //var checkstr = "";
        //if (typeof (myTree) != "undefined") {
        //    checkstr = myTree.getAllChecked();
        //    //if ((checkstr == "" || checkstr == "0") && myTree.getAllFatItems() != "") {
        //    //    alert("请先选择分类！");
        //    //    return;
        //    //}
        //}

        copyContion();//每次点击检索时将生效的查询条件存起来，避免点击分页或者列表，摘要模式时查询条件混乱
        searchResult();

    }
    //点击分页
    function searchPageNew(n) {
        $('#pageIndexNow').val(n);
        searchResult();
    }
    function searchResult() {
        var reviewForm = $('#reviewForm');
        reviewForm.submit();
    }
    function addCondition() {
        var subID = parseInt($('#currentSubid').val()) + 1;
        var len = document.getElementById("ConditionKey").options.length;
        if (subID < len) {
            var subDiv = $('#subCondition0');
            subDiv = subDiv.clone(true);
            subDiv.attr("style", "");
            subDiv.attr("id", "subCondition" + subID);
            var idstr = "SubConditionKey" + subID;
            subDiv.children("#SubConditionType0").attr("name", "SubConditionType" + subID);
            subDiv.children("#SubConditionType0").attr("id", "SubConditionType" + subID);
            subDiv.children("#SubConditionKey0").attr("name", idstr);
            subDiv.children("#SubConditionKey0").attr("id", idstr);

            subDiv.children("#SubConditionValue0").attr("name", "SubConditionValue" + subID);
            subDiv.children("#SubConditionValue0").attr("id", "SubConditionValue" + subID);

            $('#subCondition' + (subID - 1)).after(subDiv[0].outerHTML);
            $('#currentSubid').attr("value", subID);
            document.getElementById(idstr)[subID].selected = true; //选中项
            $("#SubConditionValue" + subID).attr("maxlength", 50);
            //相似词检索
            $("#SubConditionValue" + subID).keyup(smartKeyup);
        }
    }

    function delCondition() {

        var subID = parseInt($('#currentSubid').val());
        if (subID > 0) {
            $('#subCondition' + subID).remove();
            $('#currentSubid').attr("value", subID - 1);
        }
    }
    //复制原有查询条件
    function copyContion() {

        var select = $('#categoryType').val();
        if (typeof (myTree) != "undefined") {  //左侧有导航树的时候判断
            var checkstr = myTree.getAllChecked();
            $('#selectedCatTypeID').attr("value", select);
            if (checkstr != "" && checkstr != "0") {
                $('#checkedCatID').val(checkstr);
            }
            else {
                $('#checkedCatID').val("");
            }
        }
        $("#beforecheckedCatID").val($("#checkedCatID").val());
        $("#beforeselectedCatTypeID").val($("#selectedCatTypeID").val());

        $("#beforeConditionValue").val($("#ConditionValue").val());
        $("#beforeConditionKey").val($("#ConditionKey").val());
        $("#beforeQueryValue").val($("#SubConditionQuery").val());

        var subID = parseInt($('#currentSubid').val());//获取当前条件数量
        if (subID > 0) {
            $("#beforeContion").html("");
            for (var i = 1; i <= subID; i++) {
                var beforeType = "beforeConditionType" + i;//新的id
                var conType = $('#' + 'SubConditionType' + i).val();//值
                $("#beforeContion").append("<input id=" + beforeType + " name=" + beforeType + " type=\"text\" value='" + conType + "' />");

                var beforeKey = "beforeConditionKey" + i;//新的id
                var conKey = $('#' + 'SubConditionKey' + i).val();//值
                $("#beforeContion").append("<input id=" + beforeKey + " name=" + beforeKey + " type=\"text\" value='" + conKey + "' />");

                var beforeValue = "beforeConditionValue" + i;//新的id
                var contValue = $('#' + 'SubConditionValue' + i).val();//值
                $("#beforeContion").append("<input id=" + beforeValue + " name=" + beforeValue + " type=\"text\" value='" + contValue + "' />");

            }
        }

    }
    $(document).keydown(function (event) {
        if (event.keyCode == 13) {
            search();
        }
    });
    //切换排序方式
    function sortClick(sort, ename) {
        $('#pageIndexNow').val('1');
        $("#sortField").val(ename);
        if (ename == $("#sortFieldBefore").val() || $("#sortFieldBefore").val() == "") { //如果是点击排序字段本身则调整排序顺序
            if (sort == "desc") {
                $('#sortDescAsc').val('asc');
            }
            else {
                $('#sortDescAsc').val('desc');
            }
        }
        else {  //如果是点击其他排序字段，则按数据库默认排序
            var initsort = $("#sortInit").val();
            $('#sortDescAsc').val(initsort);//数据库默认排序
            $("#sortFieldBefore").val(ename);
        }

        searchResult();
    }
    function searchSingle(id) {
        copyContion();//每次点击检索时将生效的查询条件存起来，避免点击分页或者列表，摘要模式时查询条件混乱
        $('#pageIndexNow').val('1');
        $('#checkedCatID').val(id);
        $("#beforecheckedCatID").val($("#checkedCatID").val());
        var searchForm = $('#reviewForm');
        searchForm.submit();
    }
</script>
<!--内容==开始-->
<div class="wrap">

    <!--面包屑一-->
    <div class="crumbLink">
    </div>
    <div class="clearfix">
        <!-- wrap-sideL==START -->
  @if (ViewBag.CategoryType != null && ViewBag.CategoryType.Count > 0)
        {
        <div class="wrap-sideL">
            <h3 class="wrap-l-t">检索导航</h3>
            <div class="wrap-l-b">

                <div class="wrap-l-b-h">
                    选择分类导航
                    <select id="categoryType" onchange="categoryChange();">
                        @foreach (var item in ViewBag.CategoryType)
                        {          
                            <option value="@item.SysID">@item.Name</option>
                        }
                    </select>
                    @{
                        var ajaxOptions = new AjaxOptions()
                        {
                            HttpMethod = "post",
                            UpdateTargetId = "categroyList",
                            InsertionMode = InsertionMode.Replace
                        };
                        @Ajax.ActionLink("category", "GetCategroyList", "SingleSearch", new { type = 1 }, ajaxOptions, new { id = "UpdateCatLink", hidden = "hidden", style = "display:none" })
                    }
                </div>

                <div class="wrap-l-b-f">
                    <div class="tr">
                        <a onclick="checkAll()">全选</a>&nbsp;&nbsp;&nbsp;&nbsp;<a onclick="unCheckAll()">清除</a>
                    </div>
                    <div class="wrap-l-b-f-con" id="categroyList">
                    </div>
                </div>

            </div>
        </div>
  }
        <!-- wrap-sideL==END -->
        <!-- wrap-sideR==START -->
         @if (ViewBag.CategoryType != null && ViewBag.CategoryType.Count > 0)
        { 
            @Html.Raw(" <div class=wrap-sideR>")
        }
        else
        {
        
            @Html.Raw(" <div class=wrap-sideR-xl>")
        }
            <ul class="nav nav-tabs05 b0 clearfix">
                <li class="active"><a href="javascript:void(0);">@ViewBag.DisplayName</a></li>
            </ul>
            <div class="">
                @using (Ajax.BeginForm("ReViewSearch", new { }, new AjaxOptions()
                {
                    HttpMethod = "post",
                    InsertionMode = InsertionMode.Replace,
                    UpdateTargetId = "docList",
                    LoadingElementId = "loading"
                }, new { @class = "form form-h form-h-8em", id = "reviewForm" }))
                {
                    <fieldset>
                        <div class="f-gp clearfix" id="searchCondition">
                            <span class="f-btn">
                                <a href="javascript:addCondition();" class='iconfont iconfont-add'></a>
                                <a href="javascript:delCondition();" class='iconfont iconfont-minus'></a>
                            </span>
                            <select id="ConditionKey" name="ConditionKey" class='f-select span2'>
                                @foreach (var item in ViewBag.SearchField)
                                {          
                                    <option value="@item.FieldName">@item.FieldDispName</option>
                                }
                            </select>
                            <input style="height: 19px;" id="ConditionValue" name="ConditionValue" type="text" value="" class="f-text span4" maxlength="50" />
                            <select id="SubConditionQuery" name="SubConditionQuery" class='f-select span2'>
                                <option value="all">全部</option>
                                <option value="0" selected="selected">待审核</option>
                                <option value="1">未通过审核</option>
                                <option value="2">通过审核</option>
                            </select>
                            <input class="btn btn-m btn-warn-f btn-submit" type="button" value="检索" onclick="search()" />
                        </div>
                        <input type="hidden" id="beforeQueryValue" name="beforeQueryValue" value="" />
                        <input type="hidden" id="beforeConditionValue" name="beforeConditionValue" value="" />
                        <input type="hidden" id="beforeConditionKey" name="beforeConditionKey" value="" />
                        <input type="hidden" id="beforecheckedCatID" name="beforecheckedCatID" value="" />
                        <input type="hidden" id="beforeselectedCatTypeID" name="beforeselectedCatTypeID" value="" />

                        <div id="beforeContion" style="display: none"></div>
                        <input type="hidden" id="currentSubid" name="currentSubid" value="0" />
                        <input type="hidden" id="checkedCatID" name="checkedCatID" value="" />
                        <input type="hidden" id="selectedCatTypeID" name="selectedCatTypeID" value="" />
                        <input type="hidden" id="pageIndexNow" name="pageIndexNow" value="1" />
                        <input type="hidden" id="sortField" name="sortField" value="" />
                        <input type="hidden" id="sortFieldBefore" name="sortFieldBefore" value="@ViewBag.SortFiledInit" />
                        <input type="hidden" id="sortInit" name="sortInit" value="@ViewBag.SortDescInit" />
                        <input type="hidden" id="sortDescAsc" name="sortDescAsc" value="" />
                        <input type="hidden" id="listOrabst" name="listOrabst" value="" />
                        <input type="hidden" id="dbID" name="dbID" value="@ViewBag.dbID" />
                        <input type="hidden" id="dbName" name="dbName" value="@ViewBag.dbCode" />
                        <input type="hidden" id="displayName" name="displayName" value="@ViewBag.DisplayName" />
                        <input type="hidden" id="MediaType" name="MediaType" value="@ViewBag.MediaType" />
                        <div class="f-gp clearfix" id="subCondition0" style="display: none">
                            <select id="SubConditionType0" name="SubConditionType0" class='f-select span1'>
                                <option value="0">并且</option>
                                <option value="1">或者</option>
                            </select>
                            <select id="SubConditionKey0" name="SubConditionKey0" class='f-select span2'>
                                @foreach (var item in ViewBag.SearchField)
                                {          
                                    <option value="@item.FieldName">@item.FieldDispName</option>
                                }
                            </select>
                            <input id="SubConditionValue0" name="SubConditionValue0" type="text" value="" class="f-text span4">
                        </div>
                    </fieldset>
                }
            </div>
            <div id="loading" style="display: none; margin-left: 300px; margin-top: 50px; position: absolute">
                <img src="~/Images/loading.gif" width="50" />
            </div>
            <div id="docList"></div>
        @Html.Raw("</div>")
        <!-- wrap-sideR==END -->
    </div>
</div>
<!--内容==结束-->

<style>
    body:nth-of-type(1) .dhxtree_dhx_skyblue span.selectedTreeRow, body:nth-of-type(1) .dhxtree_dhx_skyblue span.selectedTreeRow_lor {
        overflow: visible;
        box-sizing: content-box;
    }
</style>
<script>
    //相似词检索
    $("#ConditionValue").keyup(smartKeyup);
</script>
